/*LICENSE_BEGIN
 * ******************************************************************
 * All original parts of SoccerScope2003 have copyright (2003) by
 * Team YowAI, represented by Mr. Shuhei Shiota
 * The Department of Creative Informatics
 * The Graduate School of Information Science and Technology
 * The University of Tokyo
 * 
 * Additional classes (except libraries in /lib) were developed by 
 * the Dainamite Robocup-Team of the DAI-Labor, TU-Berlin 
 * (www.dai-labor.de)
 * 
 * Extended/new classes/packages are:
 *   soccerscope.analyzer.LogfileAnalyzer
 *   soccerscope.daistatistic.*
 *   soccerscope.daistatistic.charts.*
 *   soccerscope.daistatistic.tools.*
 *   soccerscope.db.*
 *   soccerscope.dialog.*
 *   soccerscope.model.PlayerWorldModel
 *   soccerscope.model.SimplePlayer
 *   soccerscope.net.AgentConnector
 *   soccerscope.training.*
 *   soccerscope.training.conditions.*
 * ******************************************************************
LICENSE_END*/
package soccerscope.model;

import java.util.Iterator;
import java.util.Vector;

import soccerscope.model.PlayMode.PLAY_MODE;
import soccerscope.training.PlayerTrainingModel;
import soccerscope.training.TrainingModel;
import soccerscope.util.Time;

public class ClientScene extends Scene {
	public Player[] player;

	// public TrainingModel trainModel = null;

	public ClientScene() {
		super();
		this.player = new Player[Param.MAX_PLAYER * 2];
		for (int i = 0; i < Param.MAX_PLAYER * 2; i++)
			this.player[i] = new Player(Team.NEUTRAL);
	}

	public Iterator iterator() {
		Vector v = new Vector();
		for (int i = 0; i < Param.MAX_PLAYER * 2; i++)
			v.add(this.player[i]);
		return v.iterator();
	}

	public boolean isGoalieCatching() {
		for (int i = 0; i < Param.MAX_PLAYER * 2; i++)
			if (this.player[i].isCatching())
				return true;
		return false;
	}

	public static ClientScene createScene() {
		ClientScene testClientScene = new ClientScene();
		testClientScene.time = Time.MAX_TIME;
		testClientScene.pmode.pmode = PlayMode.PM_BeforeKickOff;
		testClientScene.ball.pos.set(0, 0);
		testClientScene.ball.mode = Ball.STAND;
		testClientScene.left.name = "TeamLeft";
		testClientScene.left.score = 0;
		testClientScene.right.name = "TeamRight";
		testClientScene.right.score = 0;
		for (int i = 0; i < Param.MAX_PLAYER; i++) {
			testClientScene.player[i].mode = Player.STAND;
			testClientScene.player[i].side = Team.LEFT_SIDE;
			testClientScene.player[i].unum = i + 1;
			testClientScene.player[i].stamina = 4000;
			testClientScene.player[i].pos.set(-Param.PITCH_MARGIN * 2 / 3
					* (i + 1),
					-(Param.PITCH_HALF_WIDTH + Param.PITCH_MARGIN / 2));
		}
		for (int i = Param.MAX_PLAYER; i < Param.MAX_PLAYER * 2; i++) {
			testClientScene.player[i].mode = Player.STAND;
			testClientScene.player[i].side = Team.RIGHT_SIDE;
			testClientScene.player[i].unum = i - Param.MAX_PLAYER + 1;
			testClientScene.player[i].stamina = 4000;
			testClientScene.player[i].pos.set(Param.PITCH_MARGIN * 2 / 3
					* (i - Param.MAX_PLAYER + 1),
					-(Param.PITCH_HALF_WIDTH + Param.PITCH_MARGIN / 2));
		}
		testClientScene.player[0].mode = Player.STAND | Player.GOALIE;
		testClientScene.player[11].mode = Player.STAND | Player.GOALIE;

		return testClientScene;
	}

	/**
	 * This method retrieves teh actual PlayMode as enum type PLAY_MODE
	 * 
	 * @return
	 */
	public PLAY_MODE getPlayModeEnum() {
		return PlayMode.allPlayModes[this.pmode.pmode];
	}

	/**
	 * This method creates a scene and adopts it in accordance to the
	 * TrainingModel!
	 * 
	 * @param tm -
	 *            the TrainingModel
	 * @return - the scene
	 */
	public static ClientScene createScene(TrainingModel tm) {
		ClientScene scene = ClientScene.createScene();
		for (int i = 0; i < tm.objectTrainingModel.length; i++) {
			if (tm.objectTrainingModel[i] instanceof PlayerTrainingModel) {
				PlayerTrainingModel ptm = (PlayerTrainingModel) tm.objectTrainingModel[i];
				scene.player[i].setPosition(ptm.getPosition());
				scene.player[i].angle = ptm.getBody_angle();
			} else {
				scene.ball.setPosition(tm.objectTrainingModel[i].getPosition());
			}
		}
		return scene;
	}

}

/**
 * $Log: ClientScene.java,v $
 * Revision 1.1.28.4  2006/11/23 09:41:02  endert
 * Added License Note at top of each *.java file.
 *
 * Revision 1.1.28.3  2006/11/13 16:50:17  endert
 * Removed CVS-Logs and author tags
 *
 * Revision 1.1.28.2  2006/07/31 13:36:25  endert
 * Added Java-Doc to constructors if missing, minor refactorings.
 * Revision 1.1.28.1 2006/07/26 15:28:27 endert
 * Formatted Code Revision 1.1 2006/03/13 07:37:44 axle moved from ROOT/src for
 * Maven 2 Buildsystem and Team/Soccerscope separation
 * 
 * Revision 1.5 2006/03/07 12:46:01 endert Merge after refactoring: - New
 * State-Interface: One Method for each action type - Action Bean removed -
 * ActionFactorys for helper methods, States calculate main-Action themselves -
 * formatted code - added State-List in Monitor (Context-Menu of Player) - other
 * smaller stuff
 * 
 * Revision 1.4.2.1 2006/02/25 22:07:24 wetzker formated
 * 
 * Revision 1.4 2006/02/22 16:04:43 endert This is done: - Rebound SoccerScope
 * to Agents (can be added or removed in config-file) - Situations now all
 * extend abstract class Situation - Refactorings: ActionBean _ removed from
 * Attributes - SoccerScope will automatically connect to host given in
 * Start-Call - Trainer uses the same host as soccerscope - Removed unused stuff
 * (old confs, bat, etc.) - Code formatted (good luck when merging) - organized
 * imports - all that i forgot to mention here Revision 1.3 2005/10/25 20:51:37
 * endert Added Training-Editor to SoccerScope, restructuring in some old
 * classes and some experimental stuff (goals, commitments, mental model)
 * 
 * Revision 1.2.10.3 2005/10/11 18:29:52 endert TrainingModel moved to
 * WorldModel (of SoccerScope)
 * 
 * Revision 1.2.10.2 2005/10/10 15:19:45 endert Updates a scene from a given
 * TrainingModel, to visualize the trainings-settings.
 * 
 * Revision 1.2.10.1 2005/10/10 11:05:12 endert New Training-Scenario Editor!
 * There exists a dialog, which opens on middle-mouse click on the field. From
 * here, the Trainings-Scenario may be specified in a more comfortable manner.
 * The Trainings-Scenario is also visualized on the Field - using the
 * TrainingModelLayer. The TrainingModel itself contains all data specified in
 * the scenario, and therefor can be serialized to HDD, using an XML-Stream
 * generator (XStream). The Scenario editor is still under development.
 * 
 * Revision 1.2 2005/06/19 19:44:36 till added parameter teamSide to constructor
 * of soccerscope.model.Player
 * 
 * Revision 1.1 2005/04/20 10:39:01 endert Fresh Team Repository installation
 * from /home/e/endert/Robocup to here.
 * 
 * Revision 1.1 2005/02/06 07:17:25 maketi Added soccerscope with connection to
 * our world model
 * 
 */

